package com.loong.seller.controller.backend;

import com.loong.common.domain.BaseQuery;
import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.seller.common.backend.param.CompanyParam;
import com.loong.seller.common.backend.param.CompanyQueryParam;
import com.loong.seller.handler.CompanyHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 企业控制器
 * @Author: hzp
 * @Date: 2020-10-26 11:11
 */
@RestController
@RequestMapping("/manage/seller/company")
public class CompanyController extends BaseBackendController {
    @Resource
    private CompanyHandler companyHandler;


    /**
     * 保存企业信息
     * @param param  企业信息
     * @return 200
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) CompanyParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->companyHandler.save(param));
    }

    /**
     * 更新企业信息
     * @param param 企业信息
     * @return 200
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) CompanyParam param){
        return  handlerExecutor.execute(()->companyHandler.update(param));
    }

    /**
     *根据id删除企业信息
     * @param id 企业id
     */
    @PostMapping("delete")
    public Result deleteById(@RequestParam("id") Long id){
        return handlerExecutor.execute(()->companyHandler.deleteById(id));
    }

    /**
     * 分页查询
     * @param baseQuery 分页对象
     * @param param 查询参数
     * @return
     */
    @PostMapping("pageQuery")
    public Result pageQuery(BaseQuery baseQuery, CompanyQueryParam param){

        return  handlerExecutor.execute(()->companyHandler.pageQuery(baseQuery,param));
    }

}
